package com.coderush.admin.sys.controller;

import com.coderush.admin.core.common.PageResult;
import com.coderush.admin.core.response.Result;
import com.coderush.admin.sys.model.dto.JobAddDto;
import com.coderush.admin.sys.model.dto.JobUpdateDto;
import com.coderush.admin.sys.model.vo.CompanyPageVo;
import com.coderush.admin.sys.model.vo.JobPageVo;
import com.coderush.admin.sys.service.JobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * PackageName com.coderush.admin.sys.controller
 *
 * @Author Eason
 * @Version v1.0
 * @ClassName JobController
 * @Date 2025/8/27
 * @Description TODO
 */
@RestController
@RequestMapping("/sys/job")
@Validated  // 类级别添加，用于方法参数校验
@Tag(name = "职位管理", description = "职位管理")
public class JobController {

    @Resource
    private JobService jobService;


    /**
     * 分页查询职位
     */
    @Operation(summary = "分页查询职位", description = "分页查询职位")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @GetMapping("/findByPage")
    public Result<PageResult<JobPageVo>> findByPage(String jobName, Integer pageNumber, Integer pageSize) throws Exception {

        var pageResult = jobService.findByPage(jobName, pageNumber, pageSize);

        return Result.buildSuccess(pageResult);
    }

    /**
     * 修改职位
     */
    @Operation(summary = "修改职位", description = "修改职位")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/update")
    public Result<Boolean> update(@Validated @RequestBody JobUpdateDto updateDto) throws Exception {
        boolean flag = jobService.update(updateDto);
        return Result.buildSuccess(flag);
    }

    /**
     * 添加职位
     */
    @Operation(summary = "添加职位", description = "添加职位")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "成功"),
            @ApiResponse(responseCode = "401", description = "未授权"),
            @ApiResponse(responseCode = "500", description = "服务器内部错误")
    })
    @PostMapping("/add")
    public Result<Boolean> add(@Validated @RequestBody JobAddDto addDto) throws Exception {
        boolean flag = jobService.add(addDto);
        return Result.buildSuccess(flag);
    }
}